*Sarah Cohodes
* This is the master file for Cohodes & Feigenbaum

cap log close
clear all
set more off, perm

/* define global parameters and paths */

/* paths */
global basepath  "M:\Massachusetts"       
global basepath2  "M:\Massachusetts\projects\charter_voting"      
global basepath3 "M:\Massachusetts\data_setup"      

global raw "$basepath\data_raw" 
global data "$basepath2\data"  
global data_clean "$basepath\data_clean" 
global do "$basepath2\programs"       
global do_setup "$basepath3\Programs"       
global output "$basepath2\output"   
global log "$basepath2\log" 
global adobase  "M:\Massachusetts" 
global saves "$raw\saves"
global lotto "$basepath\data_lotteries"

cd "$data"

set seed 123456

/* Create a log file */
local c_date = c(current_date)
local cdate = subinstr("`c_date'", " ", "_", .)
local logprefix "logfile" 
*log using "$log/`logprefix'_`cdate'.log", replace text


/* install any packages locally */
sysdir set PERSONAL "$adobase\ado\personal"
sysdir set PLUS 	"$adobase\ado\plus"
sysdir set SITE     "$adobase\ado\site"


cd "$adobase\ado\plus"

*user written commands necessary to run these programs
ado update ivreg2, update
ado update ranktest, update
ado update reclink, update
ado update center, update
ado update unique, update
ado update jarowinkler, update
ado update blindschemes, update
ado update grstyle, update
ado update libjson, update
net install ftools, from("https://github.com/sergiocorreia/ftools/raw/master/src/")
ado update reghdfe, update
ado update coefplot, update
net install educationdata, replace from("https://urbaninstitute.github.io/education-data-package-stata/")
ado update regsave, update

cd $data
/* keep this line in the config file */
/* It will provide some info about how and when the program was run */
/* See https://www.stata.com/manuals13/pcreturn.pdf#pcreturn */
di "=== SYSTEM DIAGNOSTICS ==="
di "Stata version: `c(stata_version)'"
di "Updated as of: `c(born_date)'"
di "Flavor:        `c(flavor)'"
di "Processors:    `c(processors)'"
di "OS:            `c(os)' `c(osdtl)'"
di "Machine type:  `c(machine_type)'"
di "=========================="


**************** RUN VOTING PROGRAMS *************
* See README for details on source files

***BELOW ARE DATA SETUP FILES COMMON AMONG ALL CHARTER PROJECTS***
do "$do_setup/Programs/0_data_setup.do"
*** This runs the necessary subprograms to set up the data


***BELOW ARE DATA SETUP FILES SPECIFIC TO THE VOTER PROJECT***

*Basic processing of the voter data (matching done separately)
do "$do/2.1_voter.do"

*Restrict to appropriate lottery sample
do "$do/2.2_voter_lottery.do"

*Process SIMS for baseline variables and school assignments
do "$do/2.3_baseline.do"

*Basic pull of high school graduation variables from the SIMS data
*and process with charter sample
do "$do/2.4_hsgrad.do"

*Further process NSC with projected year 12 (matched to sample)
do "$do/2.5_nsc.do"

*Match to voter file (fuzzy matching can take a long time)
do "$do/2.6_votermatch.do"

*Assemble analysis file
do "$do/2.7_voter_setup.do"

*Community voting
do "$do/2.8_dave_leip.do"

*MA and BPS files for descriptives
do "$do/2.9_ma_bps.do"


***BELOW ARE ANALYSIS FILES SPECIFIC TO THE VOTER PROJECT***
*student data
do "$do/3.1_analysis_voter.do"

*parent data
do "$do/3.2_analysis_parent.do"
do


cap log close

